<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 0px;
            top: 0px;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        let boxEle = document.querySelector(".box");

        let stop = 300;
        var timer = setInterval(() => {
            console.log("setInterval");
            // 每次定时器执行的时候 获取 box当前的left值 
            // let leftNum = boxEle.style.left;
            let leftNum = parseInt(getComputedStyle(boxEle, null)['left']);
            let speed = 5;
            // console.log(leftNum)
            // 让每一次值加上一个速度；
            if (leftNum === stop) {
                console.log("停止");
                clearInterval(timer);
            } else {
                boxEle.style.left = leftNum + speed + "px";
            }
        }, 50);




    </script>
</body>

</html>